

//根据正则匹配定义了解析链接的方法
export function getKCard(url, name) {
	var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
	var r = url.substr(1).match(reg)
	if (r != null) {
		return r[2]
	}
	return null;
}

export function judgePhone(val) {
	if (!val) return ''
	let reg = /^(.{3}).*(.{4})$/
	return val.replace(reg, '$1****$2')
}

export function judgeCard(val) {
	if (!val) return ''
	let reg = /^(.{3}).*(.{2})$/
	return val.replace(reg, '$1*************$2')
}



// 判断对象的每个成员都不为空
export function objectValueAllEmpty(object) {
	let isEmpty = false;
	if (typeof(object) != "object") {
		console.log("要判断的不是对象");
	}
	Object.keys(object).forEach(function(x) {
		if (object[x] === null || object[x] === "" || object[x] === undefined) {
			// console.log(x,object[x] === null , object[x] === "" , object[x] === undefined);
			isEmpty = true;
		}
	});
	return isEmpty;
}

export function checkIdCard(card_num) {
	let reg1 = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ //正则表达式定义身份证号正确格式

	if (!card_num) {
		return false;
	}
	let result = reg1.test(card_num);

	return result;
}

// 判断手机号格式是否正确
export function checkPhoneNumber(phone) {
	let re = /^1[3-9][0-9]{9}$/;
	let result = re.test(phone);
	return result
}
// 把obj2和obj1的key相同的值合并到obj1，不相同的忽略
export function mergeSameObjectKey(obj1, obj2) {
	Object.keys(obj2).forEach((key) => {
		if (obj1[key] != null) {
			obj1[key] = obj2[key];
		}
	});
	return obj1
}
